package com.javasm.mingming.login.service.impl;

import com.javasm.mingming.adminuser.entity.AdminUser;
import com.javasm.mingming.adminuser.service.AdminUserService;
import com.javasm.mingming.login.entity.LoginUserDetails;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author javasm
 * @version 0.1
 * @className PhoneUserDetailsService
 * @descriptioin:
 * @date 2025/1/13 15:11
 * @since jdk11
 */
@Service("phoneUserDetailsService")
public class PhoneUserDetailsService implements UserDetailsService {
    @Resource
    AdminUserService adminUserService;

    @Override
    public UserDetails loadUserByUsername(String phone) throws UsernameNotFoundException {
        AdminUser adminUser = adminUserService.getByPhone(phone);
        if (adminUser != null){
            return new LoginUserDetails(adminUser);
        }
        return null;
    }
}
